package Command;

import Server.Command;
import Server.cmdArguments;

public class PrevCommand implements Command {
	private cmdArguments args;
	private Integer i;

	public PrevCommand() {}

	@Override
	public String execute() {
		String result = "";
		try {
			i = Integer.parseInt(args.commands[1].trim());
			Integer previous = args.bst.inversedSuccessive(i);
			if (previous == -1)
				result = "NAN";
			else 
				result = "Prev " + i + ": " + previous;
		} catch (Exception e) {
			result = "Missing or incorrect argument";
		}
		return result;
	}

	@Override
	public String undo() {
		return "Undo not possible on prev command.";
	}

	@Override
	public void setArgs(cmdArguments args) {
		this.args=args;
	}

}
